package com.lzm.ydpt.module.mall.utils;

import android.text.InputFilter;
import android.text.Spanned;

public class BigValueFilter implements InputFilter {
    private int maxValue;

    //输入的最大金额
    private static final int MAX_VALUE = Integer.MAX_VALUE;

    public BigValueFilter() {
        maxValue = MAX_VALUE;
    }

    public void setMaxValue(int maxValue) {
        this.maxValue = maxValue;
    }


    @Override
    public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
        try {
            int input = Integer.parseInt(dest.toString() + source.toString());
            if (isInRange(maxValue, input))
                return null;
        } catch (NumberFormatException nfe) {
        }
        return "";
    }

    private boolean isInRange(int b, int c) {
        return c >= 1 && c <= b;
    }

}